function openAttachment() {
    $('.attachment').css('display', 'flex');
}

function closeAttachment() {
    $('.attachment').hide();
}

function onPageReady() {
    $(".title span").html("读&nbsp;政&nbsp;策");
    ajax({
        url: "/api/home/getPolicyInfo/" + $.paramToObj(window.location.href).id,
        type: "get",
        dataType: "json",
        headers: {},
        success: function (result) {
            thumb = result.data.coverImg;
            $(".main>div").render("#detail", result.data);
            $("body").render("#footer", result.data);
            if (result.data.favoured) {
                $(".collection").addClass("selected");
            }
            $(".collection").on("click", function (event) {
                event.preventDefault();
                var $this = $(this);
                ajax({
                    url: "/api/home/markFavorite",
                    type: "post",
                    dataType: "json",
                    headers: {
                        "content-type": "application/json"
                    },
                    data: JSON.stringify({
                        appUserId: getLocalItem("user") ? new AppUserBean(getLocalItem("user")).id : '',
                        status: $this.hasClass("selected") ? 0 : 1,
                        subjectId: $.paramToObj().id,
                        type: "2"
                    }),
                    success: function (result) {
                        $this.toggleClass("selected");
                    }
                });
                return false;
            });
            $('.share').on('click', function () {
                $('.shareBar').css('display', 'flex');
            });
            initPreview('img');
        }
    });
    var weixin = null, qq = null;
    try {
        plus.share.getServices(function (services) {
            for (var i in services) {
                switch (services[i].id) {
                    case 'weixin': {
                        weixin = services[i];
                        break;
                    }
                    case 'qq' : {
                        qq = services[i];
                        break;
                    }
                }
            }
        }, function (e) {
            console.log("获取分享服务列表失败：" + e.message);
        });
    } catch (e) {
    }
    $('.shareBar-bg').on('click', function () {
        $('.shareBar').hide();
    });
    window.jumpShare = function (i) {
        var service = null, extra = {};
        switch (i) {
            case 1: {
                service = weixin;
                extra = {scene: "WXSceneTimeline"};
                break;
            }
            case 2: {
                service = qq;
                break;
            }
            default: {
                service = weixin;
                extra = {scene: "WXSceneSession"}
            }
        }
        ajax({
            url: "/api/home/getPolicyDetail/" + $.paramToObj().id,
            type: "get",
            dataType: "json",
            headers: {},
            success: function (result) {
                share(service, $('.main .title').html(), result.data, thumb, extra);
            }
        });
    }
}